package org.fuys.coder.domain.act.lottery.service.draw;

import org.fuys.coder.common.entity.Pair;
import org.fuys.coder.domain.act.lottery.model.req.draw.DrawReq;
import org.fuys.coder.domain.act.lottery.model.res.draw.DrawResult;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @projectName: fuys-low-coder
 * @package: org.fuys.coder.domain.lottery.service.draw
 * @className: AbstractDrawService
 * @author: WangJing
 * @description: 抽象的抽奖结果生成类 用于定义流程
 * @date: 2024/7/7 22:42
 * @version: 1.0
 */
public abstract class AbstractDrawService implements IDrawService{

    @Override
    public DrawResult doDrawExec(DrawReq req) {
        final Integer integer = this.doDraw(req);
        return this.buildResult(integer,req);
    }


    protected abstract Integer doDraw(DrawReq req);

    protected boolean check(List<Pair<Integer,Double>> odds){
        //这里为什么不抛出异常呢 因为交给子类处理 可能有些子类对于概率信息并不是刚需
        return !ObjectUtils.isEmpty(odds);
    }

    protected abstract DrawResult buildResult(Integer integer,DrawReq req);
}
